<?php (!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');?>
{admintemplate header}
<div class="box">
	<div class="heading">
	<h1>订单管理</h1>
	<div class="buttons">
	<a href="{url admin.php?m=order}" >订单数据统计</a>
	<a href="{url admin.php?m=order&f=olist}" >商品交易订单</a>
	<a href="{url admin.php?m=order&f=olist&t=pointpay}" >积分充值订单</a>
	
	</div>
	</div>
	<div class="main">
	{if !isset($_REQUEST['f'])}
	
	
	
	{/if}
	
	{if $_REQUEST['f']=='olist'}
	<div class="search">
			<form name="search" method="GET" action="{url admin.php}">
			<input type="hidden" name="m" value="order" />
			<input type="hidden" name="f" value="olist" />
			<input type="hidden" name="mod" value="{$mod}" />
				<fieldset>
					<legend>订单搜索</legend>
						订单号：<input type="text" name="stxnid" size="19" value="{urldecode($stxnid)}" />
						购买者邮箱：<input type="text" name="smail" size="19" value="{urldecode($smail)}" />
						 订单状态：<select name="orderstatus">
						<option  value="">全部状态</option>
						{loop $status $k $v}
						<option {if $orderstatus===$k}selected="selected"{/if} value="{$k}">{$v}</option>{/loop}</select>
						<input type="submit" name="s" class="button" value="给我搜" />
				</fieldset>
			</form>
	</div>
	
	<form name="update" method="post" action="{url admin.php?m=order}">
		<input type="hidden" name="f" id="f" value="olist" />
			<table class="list" id="list" cellspacing="0">
				<thead>
				<tr>{if ican("ecdelete")}
					<td width="1">
					<input type="checkbox" class="checkbox" value="1" name="chkall" onclick="check_all(this)" />
					</td>
					{/if}
					<td>交易单号</td>
					<td>买家</td>
					<td>卖家</td>
					<td>总额(元)</td>
					<td>积分</td>
					<td>创建/结束日期</td>
					<td>支付状态</td>
					<td>支付日期</td>
					<td>订单状态</td>
					<td class="center">操作</td>
				</tr>
				</thead>
				<tbody>
				{loop $result $row}
				<tr id="row_{$row['txnid']}">
				{if ican("ecdelete")}
					<td align="center"  width="1"><input type="checkbox" name="id[]" value="{$row['txnid']}" class="checkbox" /></td>
				{/if}	
					<td>{$row['txnid']}</td>
					<td>{$row['username']}</td>
					<td>{$row['seller']}</td>
					<td >{$row['gross']}</td>
					<td >{$row['amount']}</td>
					<td >{if $row['created']>0}{gdate('Y-m-d H:i', $row['created'])}{/if} / {if $row['duedate']>0}{gdate('Y-m-d H:i', $row['duedate'])}{/if}</td>
					<td>{if $row['payment_date']>0}{$lang['hadpay']}{else}{$lang['notpay']}{/if}<span>({$lang[$row['payment_type']]})</span></td>
					<td >{if $row['payment_date']>0}{gdate('Y-m-d H:i', $row['payment_date'])}{/if}</td>
					<td>{$status[$row['status']]}</td>
					<td align="center" valign="top">
					[<a href="{url admin.php?m=order&f=detail&id=$row[txnid]}" target="_blank">详细</a>]
			{if $row['status']<1}
			[<a href="javascript:;" onclick="order_status({$row[txnid]})">确认</a>]
			{/if}
			{if $row['status']==1}
			[<a href="javascript:;" onclick="order_status({$row[txnid]})">配货</a>]
			{/if}
			{if $row['status']==2}
			[<a href="javascript:;" onclick="order_status({$row[txnid]})">配送</a>]
			{/if}
			{if $row['status']==4 || $row['status']==5}
			[<a href="javascript:;" onclick="order_status({$row[txnid]})" >结束</a>]
			{/if}
			{if $row['status']<7}
			[<a href="javascript:;" onclick="order_cancel({$row[txnid]})" >取消</a>]
			{/if}
					</td>
				</tr>
				{/loop}
				{if ican("ecdelete")}
				<tr>
					<td><input type="checkbox" class="checkbox" value="1" name="chkall" onclick="check_all(this)" /></td>
					<td colspan="10"  class="left">{pager($num,$pagesize,$page,$url)}
					<input type="button" class="button" onclick="do_submit('delete',this.form)" value="删除"/>
					</td>
				</tr>
				{/if}
				</tbody>
			</table>
	</form>
	<script type="text/javascript">
		function order_status(id){
			if(!confirm('确认执行此操作?')){return false;}
			$.getJSON("admin.php?m=order&f=status&id="+id+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					if(data.m){alert(data.m);}
					document.location.reload();
				}else{
				}
				});
			return false;
		}
		function order_cancel(id){
			if(!confirm('确定取消该交易?')){
				return false;
			}
			$.getJSON("admin.php?m=order&f=cancel&id="+id+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					if(data.m){alert(data.m);}
					document.location.reload();
				}else{
				}
				});
			return false;
		}
	</script>	
	{/if}
	
	{if $_REQUEST['f']=='detail'}
<div class="mt"><h3>商品信息</h3><div class="fr"></div></div>
	
	<table width="100%" class="uc_tableb"><tbody>
	{if $data['type']=='pointpay'}
	<tr><th colspan="6">购买积分</th></tr>
	{if $data['amount']}
	<tr><td  colspan="6">{$setting[$_G['settings']['point']['pointuse']]['title']}：{$data['amount']}</td></tr>
	{else}
	<tr><td colspan="6" >-</td></tr>
	{/if}
	{else}
						<tr>
							<th width="10%">商品编号</th>
							<th width="45%">商品名称</th>
							<th width="10%">商品单价</th>
							<th width="10%">赠送积分</th>
							<th width="10%">商品数量</th>
							<th width="100">操作</th>
						</tr>
						{loop $goods $good}
						<tr>
						    <td>{$good['pid']}</td>
						    <td>{$good['title']}</td>
						    <td><strong>￥{price($good['price'])}</strong></td>
						    {php $goodsp+=$good['price'];}
						    <td>{$good['credit']}</td>
						    <td>{$good['qty']}</td>
						    <td>{$good['sku']}</td>
						</tr>
						{/loop}
						{if empty($goods)}
						<tr><td colspan="6" >-</td></tr>
						{/if}
	{/if}	
	</tbody></table>
					    		  
			  
	<table class="uc_tableb">
		<tbody><tr><th align="left"><strong>订单信息</strong></th></tr>
		<tr><td><div>
		订单编号：{$data['txnid']}<br>
		支付方式：{$lang[$data['payment_type']]}<br>
		{if $data['shipping_type']}配送方式：{$lang[$data['shipping_type']]}<br>{/if}
		下单时间：{gdate('Y-m-d H:i:s',$data['created'])}<br>
		{if $data['trade_no']}{$lang[$data['payment_type']]}订单号：{$data['trade_no']}<br>{/if}
		</div></td></tr>
		<tr><td><div>
			<strong>收货人信息</strong><br>
			收货人姓名：{$data['firstname']}<br>
			地址：{$data['street1']} {$data['street']}&nbsp; &nbsp;邮编：{$data['zip']}<br>
			固定电话：{$data['tel']}  
			手机号码：{$data['phone']}      <br>
			电子邮件：{$data['mail']}
		</div></td></tr>
		<tr><td><div>
			<strong>订单备注</strong><br>
			{$data['data']}
		</div></td></tr>
		<tr><td><div>
			<strong>结算信息</strong><br>
商品金额：{price($goodsp)}元 + 
运费：{price($data['shipping_cost'])}元
{if $data['amount']}
 + 积分充值：{price($data['amount']*$ratio)}元
{/if} 

 = 
<strong class="h1">订单总金额：{$data['gross']}元</strong>
		</div></td></tr> 
		{if !empty($logs)}
		<tr><td><div>
			<strong>订单记录</strong><br/>
			{loop $logs $log}
			{gdate('Y-m-d H:i:s',$log['dateline'])}：操作者:&nbsp;{$log['username']},&nbsp;&nbsp;操作内容:&nbsp;{$log['data']}<br/>
			{/loop}
		</div></td></tr>{/if}
		</tbody>
	</table>	
	
	{/if}
	
	{if $_REQUEST['f']=='edit'}
<div class="mt"><h3>商品信息</h3><div class="fr"></div></div>
	
	<table width="100%" class="uc_tableb"><tbody>
	{if $data['type']=='pointpay'}
	<tr><th colspan="6">购买积分</th></tr>
	{if $data['amount']}
	<tr><td  colspan="6">{$setting[$_G['settings']['point']['pointuse']]['title']}：{$data['amount']}</td></tr>
	{else}
	<tr><td colspan="6" >-</td></tr>
	{/if}
	{else}
						<tr>
							<th width="10%">商品编号</th>
							<th width="45%">商品名称</th>
							<th width="10%">商品单价</th>
							<th width="10%">赠送积分</th>
							<th width="10%">商品数量</th>
							<th width="100">操作</th>
						</tr>
						{loop $goods $good}
						<tr>
						    <td>{$good['pid']}</td>
						    <td>{$good['title']}</td>
						    <td><strong>￥{price($good['price'])}</strong></td>
						    {php $goodsp+=$good['price'];}
						    <td>{$good['credit']}</td>
						    <td>{$good['qty']}</td>
						    <td>{$good['sku']}</td>
						</tr>
						{/loop}
						{if empty($goods)}
						<tr><td colspan="6" >-</td></tr>
						{/if}
	{/if}	
	</tbody></table>
					    		  
			  
	<table class="uc_tableb">
		<tbody><tr><th align="left"><strong>订单信息</strong></th></tr>
		<tr><td><div>
		订单编号：{$id}<br>
		支付方式：{$lang[$data['payment_type']]}<br>
		{if $data['shipping_type']}配送方式：{$lang[$data['shipping_type']]}<br>{/if}
		下单时间：{gdate('Y-m-d H:i:s',$data['created'])}<br>
		{if $data['trade_no']}{$lang[$data['payment_type']]}订单号：{$data['trade_no']}<br>{/if}
		</div></td></tr>
		<tr><td><div>
			<strong>收货人信息</strong><br>
			收货人姓名：<input type="text" name="shipping[firstname]" value="{$data['firstname']}"/><br>
			地址：{$data['street']}&nbsp; &nbsp;邮编：<input type="text" name="shipping[zip]" value="{$data['zip']}"/><br>
			固定电话：<input type="text" name="shipping[tel]" value="{$data['tel']}"/>  
			手机号码：<input type="text" name="shipping[phone]" value="{$data['phone']}"/>      <br/>
			电子邮件：<input type="text" name="shipping[mail]" value="{$data['mail']}"/>
		</div></td></tr>
		<tr><td><div>
			<strong>订单备注</strong><br/>
			<textarea  name="txn[data]" >{$data['data']}</textarea>
		</div></td></tr>
		<tr><td><div>
			<strong>结算信息</strong><br/>
商品金额：{price($goodsp)}元 + 
运费：<input type="text" name="txn[shipping_cost]" value="{price($data['shipping_cost'])}"/>元
{if $data['amount']}
 + 积分充值：<input type="text" name="txn[amount]" value="{price($data['amount']*$ratio)}"/>元
{/if} 

 = 
<strong class="h1">订单总金额：<span class="red"><input type="text" name="txn[gross]" value="{$data['gross']}"/>元</span></strong>
		</div></td></tr> 
		</tbody>
	</table>	
	
	{/if}
	</div>
</div>	
{admintemplate footer}